package com.atguigu.tingshu.user.api;

import com.atguigu.tingshu.common.annotation.GuiGuLogin;
import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.model.album.TrackInfo;
import com.atguigu.tingshu.model.user.UserPaidTrack;
import com.atguigu.tingshu.user.service.UserInfoService;
import com.atguigu.tingshu.vo.order.OrderInfoVo;
import com.atguigu.tingshu.vo.user.UserInfoVo;
import com.atguigu.tingshu.vo.user.UserPaidRecordVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@Tag(name = "用户管理接口")
@RestController
@RequestMapping("api/user/userInfo")
@SuppressWarnings({"all"})
public class UserInfoApiController {

	@Autowired
	private UserInfoService userInfoService;

	//远程调用接口:根据用户id获取用户信息
	@Operation(summary = "根据用户id获取用户信息")
	@GetMapping("/getUserInfoVo/{userId}")
	public Result<UserInfoVo> getUserInfoVo(@PathVariable(value = "userId") Long userId){
	UserInfoVo userInfoVo =  userInfoService.getUserInfo(userId);
	return Result.ok(userInfoVo);
	}

	/**
	 * 判断用户是否购买声音列表
	 * @param albumId
	 * @param trackIdList
	 * @return
	 */
	@GuiGuLogin(required = false)
	@Operation(summary = "判断用户是否购买声音列表")
	@PostMapping("userIsPaidTrack/{userId}/{albumId}")
	public Result<Map<Long,Integer>>userIsPaidTrack(@PathVariable(value = "userId") Long userId,
								  @PathVariable(value = "albumId") Long albumId,
								  @RequestBody List<Long> trackIdList){
		Map<Long,Integer> result = userInfoService.userIsPaidTrack(userId,albumId,trackIdList);
		return Result.ok(result);
	}

	//判断用户是否购买过专辑
	@GuiGuLogin
	@Operation(summary = "判断用户是否购买过专辑")
	@GetMapping("/isPaidAlbum/{itemId}/{userId}")
	public  Result<Boolean> isPaidAlbum(@PathVariable(value = "itemId")  Long itemId,
										@PathVariable(value = "userId") Long userId){
	Boolean isPaid = userInfoService.isPaidAlbum(itemId,userId);
		return Result.ok(isPaid);
	}

	//查询用户购买过哪些声音的id
	@GuiGuLogin
	@Operation(summary = "查询用户购买的声音id")
	@GetMapping("/findUserPaidTrack/{userId}/{albumId}")
	public Result<List<Long>> findUserPaidTrackId(@PathVariable(value = "userId") Long userId,
														 @PathVariable(value = "albumId") Long albumId){
	List<Long>	userPaidTrackList = userInfoService.findUserPaidTrackId(userId,albumId);
	return Result.ok(userPaidTrackList);
	}

	//添加购买记录
	@Operation(summary = "添加购买记录")
	@PostMapping("/savePaidRecord")
	public Result savePaidRecord(@RequestBody UserPaidRecordVo userPaidRecordVo){
		userInfoService.savePaidRecord(userPaidRecordVo);
		return Result.ok();
	}

}

